package mwa.cs.rq.ctrl;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.management.modelmbean.RequiredModelMBean;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mwa.cs.dao.ArDAO;
import mwa.cs.dao.DefaultAddressDAO;
import mwa.cs.dao.GenDocDAO;
import mwa.cs.dao.MeterSizeDAO;
import mwa.cs.dao.RequestDAO;
import mwa.cs.dao.RequestQuoteDAO;
import mwa.cs.database.Database;
import mwa.cs.model.DefaultAddress;
import mwa.cs.model.Request;
import mwa.cs.model.RequestQuote;
import mwa.cs.rc.ctrl.CS51002Srvl;
import mwa.cs.util.JDate;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

/**
 * Servlet implementation class CS61001Srvl
 */
public class CS61001Srvl extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private int vnSiteId;
	private int vnUserId;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CS61001Srvl() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request , response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request , response);	
	
	}

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		vnSiteId = Integer.parseInt(request.getSession().getAttribute("site_id").toString());
		vnUserId = Integer.parseInt(request.getSession().getAttribute("user_id").toString());
		
		String vaProcessType = "";
		String vaDefaultAddress = request.getParameter("vaDefaultAddress");
		
		try {
			vaProcessType =  (request.getParameter("process_type")==null)?"":request.getParameter("process_type").toString();
		} catch(NullPointerException ex){ 
			vaProcessType = "";
		} catch(Exception ex) {
		}
		if(vaProcessType.equals("calculate")){ 
			getValueCalcuate(request , response);
		} else if(vaProcessType.equals("insert") || vaProcessType.equals("update")){ 
			insert(request , response , vaProcessType);
		} else if(vaProcessType.equals("search")){
			getRequest(request, response);
		}else if (vaDefaultAddress != null && vaDefaultAddress.equals("yes")){
			getDefaultAddressData(request, response);
		}

	}

	private void insert(HttpServletRequest request, HttpServletResponse response , String processType)  throws ServletException, IOException{
		Database db = new Database();
		JSONObject voObject = new JSONObject();
		PrintWriter voOut  =  response.getWriter();
		try { 
			String vaStepOneInputName  = request.getParameter("stepOneInputName");
			String vaStepOneInputHomeNumber = request.getParameter("stepOneInputHomeNumber");
			String vaStepOneInputAddress  = request.getParameter("stepOneInputAddress");
			String vaStepOneInputCityCode = request.getParameter("stepOneInputCityCode");
			String vaStepOneInputDistrictCode = request.getParameter("stepOneInputDistrictCode");
			String vaStepOneInputProvinceCode = request.getParameter("stepOneInputProvinceCode");
			String vaStepOneInputPostCode = request.getParameter("stepOneInputPostCode");
			String vaStepOneInputTelephone = request.getParameter("stepOneInputTelephone");
			String vaStepTwoInputPname  = request.getParameter("stepTwoInputPname");
			String vaStepTwoInputFname  = request.getParameter("stepTwoInputFname");
			String vaStepTwoInputLname =  request.getParameter("stepTwoInputLname");
			String vaStepTwoInputIdCard  = request.getParameter("stepTwoInputIdCard");
			String vaStepTwoInputHomeCardId  = request.getParameter("stepTwoInputHomeCardId");
			String vaStepTwoInputHomeNumber = request.getParameter("stepTwoInputHomeNumber");
			String vaStepTwoInputAddress = request.getParameter("stepTwoInputAddress");
			String vaStepTwoInputCityCode  = request.getParameter("stepTwoInputCityCode");
			String vaStepTwoInputDistrictCode = request.getParameter("stepTwoInputDistrictCode");
			String vaStepTwoInputProvinceCode = request.getParameter("stepTwoInputProvinceCode");
			String vaStepTwoInputPostCode = request.getParameter("stepTwoInputPostCode");
			String vaStepTwoTelephoneUser = request.getParameter("stepTwoInputTelephoneUser");
			String vaStepTwoInputNameContact  = request.getParameter("stepTwoInputNameContact");
			String vaStepTwoInputHomeNumberContact = request.getParameter("stepTwoInputHomeNumberContact");
			String vaStepTwoInputAddressContact = request.getParameter("stepTwoInputAddressContact");
			String vaStepTwoInputCityCodeContact = request.getParameter("stepTwoInputCityCodeContact");
			String vaStepTwoInputDistrictCodeContact  = request.getParameter("stepTwoInputDistrictCodeContact");
			String vaStepTwoInputProvinceCodeContact  = request.getParameter("stepTwoInputProvinceCodeContact");
			String vaStepTwoInputPostCodeContact = request.getParameter("stepTwoInputPostCodeContact");
			String vaStepTwoTelephoneContact = request.getParameter("stepTwoInputTelephoneContact");
			String vaStenTwoInputGarbageCharge  = request.getParameter("stenTwoInputGarbageCharge");
			String vaStepTwoInputWasteWaterCharge = request.getParameter("stepTwoInputWasteWaterCharge");
			String vaStepTwoInputOtherCharage = request.getParameter("stepTwoInputOtherCharage");
			String vaStepThreeInputCustomerType = request.getParameter("stepThreeInputCustomerType");
			String vaStepThreeInputCustomerClass = request.getParameter("stepThreeInputCustomerClass");
			String vaStepThreeInputAllowance = request.getParameter("stepThreeInputAllowance");
			String[] vaStepThreeInputDocument = request.getParameterValues("stepThreeInputDocument[]");
			String vaStepThreeInputMeterSize = request.getParameter("stepThreeInputMeterSize");
			String[] vaStepThreeInputCalculateMoneyAmount  = request.getParameterValues("stepThreeInputCalculateMoneyAmount[]");
			String vaStepThreeInputCalculateMoney = request.getParameter("stepThreeInputCalculateMoney");
			
			
			RequestDAO voRequestDAO = new RequestDAO(db);
			GenDocDAO voGenDocDAO = new GenDocDAO(db);
			JDate voDate  = new  JDate();
			
			Request  voRequestModel = new Request();
			voRequestModel.setVnSiteId(vnSiteId);
			
			// Site
			String vaRequestNumber = voGenDocDAO.generatingNextRQDoc(vnSiteId, voDate.getMonth() , voDate.getYear());
			voRequestModel.setVaRequestNumber(vaRequestNumber);
			voRequestModel.setVaRequestGroup("0");
			voRequestModel.setVaRequestType("01");
			voRequestModel.setVaStatus("1");
			voRequestModel.setVaApplicantName(vaStepOneInputName);
			voRequestModel.setVaApplicantHomeNumber(vaStepOneInputHomeNumber);
			voRequestModel.setVaApplicantAddress(vaStepOneInputAddress);
			voRequestModel.setVaApplicantCityCode(vaStepOneInputCityCode);
			voRequestModel.setVaApplicantDistrictCode(vaStepOneInputDistrictCode);
			voRequestModel.setVaApplicantProvinceCode(vaStepOneInputProvinceCode);
			voRequestModel.setVaApplicantPostCode(vaStepOneInputPostCode);
			voRequestModel.setVaApplicantTelephone(vaStepOneInputTelephone);
			
			// Data
			voRequestModel.setVaPName(vaStepTwoInputPname);
			voRequestModel.setVaFName(vaStepTwoInputFname);
			voRequestModel.setVaLName(vaStepTwoInputLname);
			voRequestModel.setVaCardId(vaStepTwoInputIdCard);
			voRequestModel.setVaAddress(vaStepTwoInputAddress);
			voRequestModel.setVaHouseId(vaStepTwoInputHomeCardId);
			voRequestModel.setVaHomeNumber(vaStepTwoInputHomeNumber);
			voRequestModel.setVaCityCode(vaStepTwoInputCityCode);
			voRequestModel.setVaDistrictCode(vaStepTwoInputDistrictCode);
			voRequestModel.setVaProvinceCode(vaStepTwoInputProvinceCode);
			voRequestModel.setVaPostCode(vaStepTwoInputPostCode);
			voRequestModel.setVaTelephone(vaStepTwoTelephoneUser);
			
			voRequestModel.setVaContactName(vaStepTwoInputNameContact);
			voRequestModel.setVaContactHomeNumber(vaStepTwoInputHomeNumberContact);
			voRequestModel.setVaContactAddress(vaStepTwoInputAddressContact);
			voRequestModel.setVaContactCityCode(vaStepTwoInputCityCodeContact);
			voRequestModel.setVaContactDistrictCode(vaStepTwoInputDistrictCodeContact);
			voRequestModel.setVaContactProvinceCode(vaStepTwoInputProvinceCodeContact);
			voRequestModel.setVaContactPostCode(vaStepTwoInputPostCodeContact);
			voRequestModel.setVaContactTelephone(vaStepTwoTelephoneContact);
			
			double waterCharge = 0;
			if(!vaStepTwoInputWasteWaterCharge.equals(null) && !vaStepTwoInputWasteWaterCharge.equals("")){
				waterCharge = Double.parseDouble(vaStepTwoInputWasteWaterCharge);
			}
			voRequestModel.setVnWastewaterCharge(waterCharge);
			
			double  garbageCharge  = 0;
			if(!vaStenTwoInputGarbageCharge.equals(null) && !vaStenTwoInputGarbageCharge.equals("")){
				garbageCharge = Double.parseDouble(vaStenTwoInputGarbageCharge);
			}
			voRequestModel.setVnGarbageCharge(garbageCharge);
			
			double otherCharge  = 0;
			if(!vaStepTwoInputOtherCharage.equals(null) && !vaStepTwoInputOtherCharage.equals("")){
				otherCharge = Double.parseDouble(vaStepTwoInputOtherCharage);
			}
			voRequestModel.setVnOtherCharge(otherCharge);
			
			voRequestModel.setVaDocumentType(getDocumentId(request));
			voRequestModel.setVaDocumentReference(getDocumentDescrip(request));
			
			voRequestModel.setVaCustomerClass(vaStepThreeInputCustomerClass);
			voRequestModel.setVaCustomerType(vaStepThreeInputCustomerType);
			
			voRequestModel.setVaAllowance(vaStepThreeInputAllowance);
			
			voRequestModel.setVaMeterSize(vaStepThreeInputMeterSize);
			
			
			voRequestModel.setVnInsertUserId(vnUserId);
			voRequestModel.setVaInsertDate(voDate.getDate());
			voRequestModel.setVaInsertTime(voDate.getTime());
			
			voRequestModel.setVnUpdateUserId(vnUserId);
			voRequestModel.setVaUpdateDate(voDate.getDate());
			voRequestModel.setVaUpdateTime(voDate.getTime());

			if(processType.equals("update")){
				String requestNumber = request.getParameter("request_number");
				RequestQuoteDAO voRequestQuoteDAO   = new RequestQuoteDAO(db);
				voRequestQuoteDAO.deleteRequestQuote("REQUEST_NUMBER = "+requestNumber);		
				voRequestDAO.deleteRequest("REQUEST_NUMBER = "+requestNumber);
			}

			voRequestDAO.insertRequest(voRequestModel);
			db.commit();
			
			if (vaStepThreeInputCalculateMoney.equals("Y")){
				addReceiveQout(request, vaRequestNumber, vnSiteId, vnUserId);
			}

			
			

			voObject.put("result", "success");
			voObject.put("RequestNumber", vaRequestNumber);
			voOut.print(voObject.toJSONString());
			
		}catch (Exception ex){ 
			ex.printStackTrace();
			
			voObject.put("result", "fail");
			voOut.print(voObject.toJSONString());
		}finally{
			db.close();
		}
	}
	
	private void getValueCalcuate(HttpServletRequest request,
			HttpServletResponse response)  throws ServletException, IOException{
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/JSON");
		Database db = new Database();

		int vnMeterSizeCode =  0;
		try { 
			vnMeterSizeCode  =  Integer.parseInt(request.getParameter("meterSizeCode"));
			try {
				JSONObject voObject = new JSONObject();
				JSONArray voRow = new JSONArray();
				PrintWriter voOut = response.getWriter();
				MeterSizeDAO  voMeterSizeDAO   = new MeterSizeDAO(db);
				List<Map<String, Object>> voListFindAll;				
				voListFindAll  =  voMeterSizeDAO.getValueCalcuate(vnSiteId , vnMeterSizeCode);
				List voListResutl = new LinkedList();
				for (int i = 0; i < voListFindAll.size(); i++) {
					Map<String, Object> voMapItem = (Map<String, Object>) voListFindAll.get(i);
					Map item = new HashMap();
					item.put("RECEIVE_CODE", voMapItem.get("RECEIVE_CODE"));
					item.put("DESCRIPTION", voMapItem.get("DESCRIPTION"));
					item.put("FEE", voMapItem.get("FEE"));
					voListResutl.add(item);
				}
				voOut.print(JSONValue.toJSONString(voListResutl));
			} catch (Exception ex) {
			} finally { 
				db.close();
			}
		}catch(Exception ex){ 
		}
	}

	/**
	 * this get document id for input document.
	 * @param request
	 * @return String id [ ex. 1,2,3 ]
	 * @throws ServletException
	 * @throws IOException
	 */
	private String getDocumentId(HttpServletRequest request) throws ServletException, IOException{ 
		String[] vaDocument  = request.getParameterValues("stepThreeInputDocument[]");
		String vaId  = "";
		if(vaDocument!=null){
			for (int i=0; i<vaDocument.length; i++) {
				if(vaDocument.length == 1 || i == (vaDocument.length-1)){ 
					vaId += vaDocument[i];
				}else{
					vaId += vaDocument[i] + ",";
				}
			}
			return vaId;	
		}else{
			return null;
		}
		
	}
	
	/**
	 * this get description document type 
	 * @param request
	 * @return String description 
	 * @throws ServletException
	 * @throws IOException
	 */
	private String getDocumentDescrip(HttpServletRequest request) throws ServletException, IOException {
		String[] vaDocument  = request.getParameterValues("stepThreeInputDocument[]");
		String vaDescription  = "";
		if(vaDocument!=null){
			for (String string : vaDocument) {
				if(string.equals("4")){ 
					vaDescription = request.getParameter("stepThreeInputComment");
				} else { 
					vaDescription = "";
				}
			}
			return vaDescription;
		}else{
			return null;
		}
	}
	
	/**
	 * this is save data REQUEST_QOUTE for calculate
	 * @param request
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	private boolean addReceiveQout(HttpServletRequest request , String paRequestNumber , int vnSiteId , int vaUserIdInsert) throws ServletException , IOException { 

		JDate voDate  = new  JDate();
		Database  db  =  new Database();
		boolean  vbAction  = false ;
		 try  { 
			 
			  String[]  vaReceiveCodeArr  = request.getParameterValues("stepThreeInputReceiveCode[]");
			  String[]  vaReceiveFeeArr  =  request.getParameterValues("stepThreeInputCalculateMoneyAmount[]");

			 
			  DecimalFormat voDecimalFormat = new DecimalFormat("#.##");
			  db.beginTransaction();
			  
 
			  for(int i=0; i<vaReceiveCodeArr.length; i++){ 
				  	RequestQuoteDAO requestQuoteDAO   = new RequestQuoteDAO(db);
				  	double vnVAT = Double.parseDouble(requestQuoteDAO.getVAT(vaReceiveCodeArr[i], voDate.getDate()));
				  	double vntotalAmount = Double.parseDouble(vaReceiveFeeArr[i]);
				  	double vnvatAmount = vntotalAmount * vnVAT;
				  	double vnReceiveAmount = vntotalAmount - vnvatAmount;
  	
				  	RequestQuote requestQuote = new RequestQuote();
				  	requestQuote.setVnSiteId(vnSiteId);
				  	requestQuote.setVaRequestNumber(paRequestNumber);
				  	requestQuote.setVaReceiveCode(vaReceiveCodeArr[i]);
				  	requestQuote.setVnReceiveAmount(Double.valueOf(voDecimalFormat.format(vnReceiveAmount)));
				  	requestQuote.setVnVatAmount(Double.valueOf(voDecimalFormat.format(vnvatAmount)));
				  	requestQuote.setVnTotalAmount(Double.valueOf(voDecimalFormat.format(vntotalAmount)));
				  	requestQuote.setVnInsertUserId(vaUserIdInsert);
				  	requestQuote.setVaInsertDate(voDate.getDate());
				  	requestQuote.setVaInsertTime(voDate.getTime());
				  	requestQuote.setVnUpdateUserId(vaUserIdInsert);
				  	requestQuote.setVaUpdateDate(voDate.getDate());
				  	requestQuote.setVaUpdateTime(voDate.getTime());
				  	
				  	requestQuoteDAO.insertRequestQuote(requestQuote);
			  }
			  db.commit();
			  
			  
			  
		 }catch (Exception ex) { 
			 ex.printStackTrace();
		 } finally{
			 db.close();
		 }
		 return vbAction;
	}
	
	@SuppressWarnings("unchecked")
	private void getDefaultAddressData(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String[] vaDefaultAddressArray = null;
		Database db = new Database();
		DefaultAddressDAO voDefaultAddressDAO = new DefaultAddressDAO(db);
		DefaultAddress voDefaultAddress = voDefaultAddressDAO.getDefaultAddressBySiteId(vnSiteId);
		vaDefaultAddressArray = new String[4];
		vaDefaultAddressArray[0] = voDefaultAddress.getVaProvinceCode();
		vaDefaultAddressArray[1] = voDefaultAddress.getVaDistrictCode();
		vaDefaultAddressArray[2] = voDefaultAddress.getVaCityCode();
		vaDefaultAddressArray[3] = voDefaultAddress.getVaPostCode();

		PrintWriter voOut = response.getWriter();
		try {
			JSONObject voObject = new JSONObject();			
			JSONArray voList = new JSONArray();
			if (vaDefaultAddressArray != null) {
				for (int i = 0; i < vaDefaultAddressArray.length; i ++) {
					voList.add(vaDefaultAddressArray[i]);
				}
			}
			voObject.put("vaDefaultAddressArray", voList);
			voOut.print(voObject.toJSONString());
		} finally {
			voOut.close();
		}	
	}
	
	@SuppressWarnings("unchecked")
	public void getRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {	
		Database db = new Database();
		PrintWriter voOut = response.getWriter();
		JSONObject voObject = new JSONObject();
		RequestDAO voRequestDAO = new RequestDAO(db);
		RequestQuoteDAO voRequestQuoteDAO = new RequestQuoteDAO(db);
		String vaRequestNumber = request.getParameter("request_number");
		Map<String, Object> voMap =  voRequestDAO.getRequestByStatus(vnSiteId, vaRequestNumber,"1");
		if(voMap != null){
			voObject.put("request_number", verifyString(voMap.get("REQUEST_NUMBER")));
			voObject.put("applicant_name", verifyString(voMap.get("APPLICANT_NAME")));
			voObject.put("applicant_home_number", verifyString(voMap.get("APPLICANT_HOME_NUMBER")));
			voObject.put("applicant_address", verifyString(voMap.get("APPLICANT_ADDRESS")));
			voObject.put("applicant_city_code", verifyString(voMap.get("APPLICANT_CITY_CODE")));
			voObject.put("applicant_district_code", verifyString(voMap.get("APPLICANT_DISTRICT_CODE")));
			voObject.put("applicant_province_code", verifyString(voMap.get("APPLICANT_PROVINCE_CODE")));
			voObject.put("applicant_post_code", verifyString(voMap.get("APPLICANT_POST_CODE")));
			voObject.put("applicant_telephone", verifyString(voMap.get("APPLICANT_TELEPHONE")));

			voObject.put("pname", verifyString(voMap.get("PNAME")));
			voObject.put("fname", verifyString(voMap.get("FNAME")));
			voObject.put("lname", verifyString(voMap.get("LNAME")));
			voObject.put("card_id", verifyString(voMap.get("CARD_ID")));
			voObject.put("house_id", verifyString(voMap.get("HOUSE_ID")));
			voObject.put("home_number", verifyString(voMap.get("HOME_NUMBER")));
			voObject.put("address", verifyString(voMap.get("ADDRESS")));
			voObject.put("city_code", verifyString(voMap.get("CITY_CODE")));
			voObject.put("district_code", verifyString(voMap.get("DISTRICT_CODE")));
			voObject.put("province_code", verifyString(voMap.get("PROVINCE_CODE")));
			voObject.put("post_code", verifyString(voMap.get("POST_CODE")));
			voObject.put("telephone", verifyString(voMap.get("TELEPHONE")));
			
			voObject.put("contact_name", verifyString(voMap.get("CONTACT_NAME")));
			voObject.put("contact_home_number", verifyString(voMap.get("CONTACT_HOME_NUMBER")));
			voObject.put("contact_address", verifyString(voMap.get("CONTACT_ADDRESS")));
			voObject.put("contact_city_code", verifyString(voMap.get("CONTACT_CITY_CODE")));
			voObject.put("contact_district_code", verifyString(voMap.get("CONTACT_DISTRICT_CODE")));
			voObject.put("contact_province_code", verifyString(voMap.get("CONTACT_PROVINCE_CODE")));
			voObject.put("contact_post_code", verifyString(voMap.get("CONTACT_POST_CODE")));
			voObject.put("contact_telephone", verifyString(voMap.get("CONTACT_TELEPHONE")));
			
			voObject.put("wastewate_charge", verifyString(voMap.get("WASTEWATER_CHARGE")));
			voObject.put("garbage_charge", verifyString(voMap.get("GARBAGE_CHARGE")));
			voObject.put("other_charge", verifyString(voMap.get("OTHER_CHARGE")));
			
			voObject.put("allowance", verifyString(voMap.get("ALLOWANCE")));
			voObject.put("customer_class", verifyString(voMap.get("CUSTOMER_CLASS")));
			voObject.put("customer_type", verifyString(voMap.get("CUSTOMER_TYPE")));
			
			voObject.put("document_type", verifyString(voMap.get("DOCUMENT_TYPE")));
			voObject.put("document_reference", verifyString(voMap.get("DOCUMENT_REFERENCE")));
			
			voObject.put("meter_size", verifyString(voMap.get("METER_SIZE")));

			voObject.put("message", "yes");
		}else{
			voObject.put("message", "no");	
		}
		
		
		List<Map<String, Object>> voResult = voRequestQuoteDAO.getRequestQuote(vnSiteId, vaRequestNumber);

		if(voResult.size()!=0){
			voObject.put("calculate_money", "Y");
		}else{
			voObject.put("calculate_money", "N");
		}
		
		String[] voReceiveCode = new String[voResult.size()];
		String[] voReceiveDesc = new String[voResult.size()];
		String[] voReceiveAmount = new String[voResult.size()];
		for (int i = 0; i < voResult.size(); i++) {
			voMap = voResult.get(i);
			voReceiveCode[i] = voMap.get("RECEIVE_CODE").toString();
			voReceiveDesc[i] = voMap.get("RECEIVE_DESC").toString();
			voReceiveAmount[i] = voMap.get("RECEIVE_AMOUNT").toString();
		}
		JSONArray voListReceiveCode = new JSONArray();
		if (voReceiveCode != null) {
			for (int i = 0; i < voReceiveCode.length; i++) {
				voListReceiveCode.add(voReceiveCode[i]);
			}
		}
		
		JSONArray voListReceiveDesc = new JSONArray();
		if (voReceiveDesc != null) {
			for (int i = 0; i < voReceiveDesc.length; i++) {
				voListReceiveDesc.add(voReceiveDesc[i]);
			}
		}
		
		JSONArray voListReceiveAmount = new JSONArray();
		if (voReceiveAmount != null) {
			for (int i = 0; i < voReceiveAmount.length; i++) {
				voListReceiveAmount.add(voReceiveAmount[i]);
			}
		}
		
		voObject.put("receive_code", voListReceiveCode);
		voObject.put("receive_desc", voListReceiveDesc);
		voObject.put("receive_amount", voListReceiveAmount);
		db.close();
		voOut.print(voObject.toJSONString());
	}
	
	public Object verifyString(Object paValues){
		if(paValues != null){
			paValues = paValues.toString();
		}
		return paValues;
	}
}
